//指定数组初始化大小：
var arr_names: number[] = new Array(4)
for (var i = 0; i < arr_names.length; i++) {
    arr_names[i] = i * 2
    console.log(arr_names[i])
}
//直接初始化数组元素
var sites: string[] = new Array("Google", "Runoob", "Taobao", "Facebook")
for (var i = 0; i < sites.length; i++) {
    console.log(sites[i])
}

//数组迭代我们可以使用 for 语句来循环输出数组的各个元素：
var j: any;
var nums: number[] = [1001, 1002, 1003, 1004]
for (j in nums) {
    console.log(nums[j])
}
//数组作为参数传递给函数使用
var sites: string[] = new Array("Google", "Runoob", "Taobao", "Facebook")
function disp(arr_sites: string[]) {
    for (var i = 0; i < arr_sites.length; i++) {
        console.log(arr_sites[i])
    }
}
disp(sites);

function isBigEnough(element, index, array) {
    return (element >= 10);
}

var passed = [12, 5, 8, 130, 44].every(isBigEnough);
console.log("Test Value : " + passed); // false
//检测数值元素，并返回符合条件所有元素的数组。
function Enough(element, index, array) {
    return (element >= 10);
}

var passe = [12, 5, 8, 130, 44].filter(Enough);
console.log("Test Value : " + passe); // 12,130,44

//indexOf
var index = [12, 5, 8, 130, 44].indexOf(8);
console.log("index is : " + index);  // 2

//join()

var arr111 = new Array("First", "Second", "Third");

var str112 = arr.join();
console.log("str : " + str112);  // First,Second,Third 

var str113 = arr.join(", ");
console.log("str : " + str113);  // First, Second, Third

var str114 = arr.join(" + ");
console.log("str : " + str114);  // First + Second + Third

//lastIndexOf
var index = [12, 5, 8, 130, 44].lastIndexOf(8);
console.log("index is : " + index);  // 2

//map()
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
console.log("roots is : " + roots);  // 1,2,3

//pop()
var numbers = [1, 4, 9];

var element = numbers.pop();
console.log("element is : " + element);  // 9

var element = numbers.pop();
console.log("element is : " + element);  // 4

//push()
var numbers = new Array(1, 4, 9);
var length = numbers.push(10);
console.log("new numbers is : " + numbers);  // 1,4,9,10 
length = numbers.push(20);
console.log("new numbers is : " + numbers);  // 1,4,9,10,20

//reverse()
var arr = [0, 1, 2, 3].reverse();
console.log("Reversed array is : " + arr);  // 3,2,1,0
//shift()
var arr123 = [10, 1, 2, 3].shift();
console.log("Shifted value is : " + arr123);  // 10

//sort()
var arr145 = new Array("orange", "mango", "banana", "sugar");
var sorted = arr145.sort();
console.log("Returned string is : " + sorted);  // banana,mango,orange,sugar

//splice()
var arr234 = ["orange", "mango", "banana", "sugar", "tea"];
var removed = arr234.splice(2, 0, "water");
console.log("After adding 1: " + arr);    // orange,mango,water,banana,sugar,tea 
console.log("removed is: " + removed);

var remov = arr234.splice(3, 1);
console.log("After removing 1: " + arr);  // orange,mango,water,sugar,tea 
console.log("removed is: " + removed);  // banana

//unshift()向数组的开头添加一个或更多元素，并返回新的长度。
var arr247 = new Array("orange", "mango", "banana", "sugar");
var length = arr247.unshift("water");
console.log("Returned array is : " + arr247);  // water,orange,mango,banana,sugar 
console.log("Length of the array is : " + length); // 5
